package com.atguigu.xuexiplus.mapper;

import com.atguigu.xuexiplus.entity.UserAnswer;
import com.atguigu.xuexiplus.dto.SubmissionDetailsVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserAnswerMapper {

    @Insert("INSERT INTO user_answer (submission_id, question_id, user_answer, correct_answer, is_correct) " +
            "VALUES (#{submissionId}, #{questionId}, #{userAnswer}, #{correctAnswer}, #{isCorrect})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserAnswer answer);

    @Select("SELECT ua.question_id AS questionId, q.type, q.content, q.option_a AS optionA, q.option_b AS optionB, q.option_c AS optionC, q.option_d AS optionD, " +
            "ua.user_answer AS userAnswer, ua.correct_answer AS correctAnswer, ua.is_correct AS isCorrect " +
            "FROM user_answer ua JOIN question q ON ua.question_id = q.id WHERE ua.submission_id = #{submissionId}")
    java.util.List<SubmissionDetailsVO.Item> listDetailsBySubmissionId(@Param("submissionId") Long submissionId);
}


